﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KetBanBonPhuong;
using System.Data.SqlClient;
using Telerik.Web.UI;

public partial class Admin_UserControls_AdminManagement : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button_new_Click(object sender, EventArgs e)
    {
        Admin admin = new Admin();
        admin.Email = emailRadTextBox1.Text;
        admin.Password = Encrypt.MD5Encrypt(passwordRadTextBox2.Text);
        try
        {
            Admin.Insert(admin);
        }
        catch (SqlException)
        {
            return;
        }
        //resultLabel.Text = "Thêm mới thành công!";
        ClearData();
    }
    protected void Button_cancel_Click(object sender, EventArgs e)
    {

    }
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        DataTable dt = Admin.GetAll();
        RadGrid1.DataSource = dt;
        RadGrid1.DataBind();
    }

    protected void ClearData()
    {
        emailRadTextBox1.Text = "";
        passwordRadTextBox2.Text = "";
        repasswordRadTextBox1.Text = "";
    }
    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridDataItem row = (GridDataItem)e.Item;
        int AdminID = Convert.ToInt32(row["admin_id"].Text);
        Admin admin = Admin.GetInfo(AdminID);
        admin_idLabel.Text = admin.Admin_id.ToString();
        emailRadTextBox1.Text = admin.Email;

    }
    protected void Button_edit_Command(object sender, CommandEventArgs e)
    {
        //if (admin_idLabel.Text == "") 
        //{
        //    resultLabel.Text = "(*) Chưa chọn Admin!";
        //    return;
        //}
        //int AdminID = Convert.ToInt32(admin_idLabel.Text);
        //Admin admin = Admin.GetInfo(AdminID);
        //admin.Email = emailRadTextBox1.Text;
        //admin.Password = Encrypt.MD5Encrypt(passwordRadTextBox2.Text);
        //try
        //{
        //    Admin.Update(admin);
        //}
        //catch (SqlException)
        //{
        //    resultLabel.Text = "(*) Lỗi csdl";
        //    return;
        //}
        //resultLabel.Text = "(*) Sửa thành công!";
    }
}
